### Why So Secretive? Unpacking Attitudes Towards Secrecy and Success
### Rachel Myrick
## Replication Data for The Journal of Politics

##Data Prep and Cleaning for Experiments 1-3 (in Manuscript)
## All experiments fielded November 2018 via Lucid Academic Marketplace
## Use to construct data from raw files
## Use constructed data with myrick2019_rep_main.do file for central analysis

library(car)
library(stringr)
library(lubridate)
library(ggplot2)

### SET WORKING DIRECTORY FIRST
setwd("")

# Experiment 1 (Military Operations) -----------------------------

e = read.csv("3_exp1_raw.csv", stringsAsFactors = FALSE)

e$start_time = str_sub(e$start_time, 10, -1)
e$start_time = parse_date_time(e$start_time, order = "H:M")

e$rmm_starttime = str_sub(e$rmm_starttime, 1, -4)
e$rmm_starttime = parse_date_time(e$rmm_starttime, order = "H:M")

e$time_pretreat = as.numeric(difftime(e$rmm_starttime, e$start_time, units = "mins"))

e = subset(e, time_pretreat > 3)

#Code Civil War Scenario Outcomes
e$RMM201_t2 = ifelse(e$RMM201_nocov=="", "Covert", "Not Covert")
e$RMM201 = ifelse(e$RMM201_nocov!="", e$RMM201_nocov, e$RMM202_cov)

#Separate Scenarios

dict = subset(e, select = c("caseid", "RMM101", "RMM102", 
                           "dict_region", "RMM101_t1", "RMM101_t2",
                           "RMM102_t3"))

civ = subset(e, select = c("caseid", "RMM201", "RMM202", 
                           "civ_region", "RMM201_t1", "RMM201_t2",
                           "RMM202_t3"))

# Clean Dictator Scenario

dict$region = dict$dict_region
dict$region = ifelse(dict$region=="the Middle East", "Middle East", dict$region)

dict$approve_before = car::recode(dict$RMM101, "'Disapprove Strongly'=1;
                             'Disapprove Somewhat'=2;
                             'Disapprove Slightly'=3;
                             'Neutral'=4;
                             'Approve Slightly'=5;
                             'Approve Somewhat'=6;
                             'Approve Strongly'=7")

dict$approve_b_before = ifelse(dict$approve_before > 4, 1, 0)

dict$approve_after = car::recode(dict$RMM102, "'Disapprove Strongly'=1;
                             'Disapprove Somewhat'=2;
                             'Disapprove Slightly'=3;
                             'Neutral'=4;
                             'Approve Slightly'=5;
                             'Approve Somewhat'=6;
                             'Approve Strongly'=7")

dict$approve_b_after = ifelse(dict$approve_after > 4, 1, 0)

dict$military = ifelse(dict$RMM101_t1=="send in a small military force to assist the rebels.", 1, 0)

dict$covert = ifelse(dict$RMM101_t2=="The government informed the American public about the operation.", 0, 1)

dict$success = ifelse(dict$RMM102_t3=="successful in removing the dictator from power and the situation has stabilized.", 1, 0)

dict$dict = rep(1, nrow(dict))

dict = subset(dict, select = c(caseid, region, approve_before, 
                             approve_after, approve_b_before,
                             approve_b_after, military, 
                             covert, success, dict))

# Clean Civil War Scenario

civ$region = civ$civ_region
civ$region = ifelse(civ$region=="the Middle East", "Middle East", civ$region)

civ$approve_before = car::recode(civ$RMM201, "'Disapprove Strongly'=1;
                             'Disapprove Somewhat'=2;
                             'Disapprove Slightly'=3;
                             'Neutral'=4;
                             'Approve Slightly'=5;
                             'Approve Somewhat'=6;
                             'Approve Strongly'=7")

civ$approve_b_before = ifelse(civ$approve_before > 4, 1, 0)

civ$approve_after = car::recode(civ$RMM202, "'Disapprove Strongly'=1;
                            'Disapprove Somewhat'=2;
                            'Disapprove Slightly'=3;
                            'Neutral'=4;
                            'Approve Slightly'=5;
                            'Approve Somewhat'=6;
                            'Approve Strongly'=7")

civ$approve_b_after = ifelse(civ$approve_after > 4, 1, 0)

civ$military = ifelse(civ$RMM201_t1=="send in a small military force to assist the rebels.", 1, 0)

civ$covert = ifelse(civ$RMM201_t2=="Covert", 1, 0)

civ$success = ifelse(civ$RMM202_t3=="successful in supporting the rebels and the civil war has ended.", 1, 0)

civ$dict = rep(0, nrow(civ))

civ = subset(civ, select = c(caseid, region, approve_before, 
                             approve_after, approve_b_before,
                             approve_b_after, military, 
                             covert, success, dict))
full1 = rbind(civ, dict)

#write.csv(full1, "2_exp1_data.csv")

# Experiment 2 (Public Disapproval) --------------------------------------

e = read.csv("3_exp2_raw.csv", stringsAsFactors = FALSE)

# Remove speeders (pre-treatment)

e$start_time = str_sub(e$start_time, 10, -1)
e$start_time = parse_date_time(e$start_time, order = "H:M")

e$rmm_starttime = str_sub(e$rmm_starttime, 1, -4)
e$rmm_starttime = parse_date_time(e$rmm_starttime, order = "H:M")

e$time_pretreat = as.numeric(difftime(e$rmm_starttime, e$start_time, units = "mins"))

e = subset(e, time_pretreat > 3)

#Code Civil War Scenario Outcomes
e$RMM201_t2 = ifelse(e$RMM201_nocov=="", "Covert", "Not Covert")
e$RMM201 = ifelse(e$RMM201_nocov!="", e$RMM201_nocov, e$RMM202_cov)

#Separate Scenarios

dict = subset(e, select = c("caseid", "RMM101", "RMM102", 
                            "dict_region", "RMM101_t1", "RMM101_t2",
                            "RMM102_t3", "RMM_mcheck"))

civ = subset(e, select = c("caseid", "RMM201", "RMM202", 
                           "civ_region", "RMM201_t1", "RMM201_t2",
                           "RMM202_t3", "RMM_mcheck"))

# Clean Dictator Scenario

dict$region = dict$dict_region
dict$region = ifelse(dict$region=="the Middle East", "Middle East", dict$region)

dict$approve_before = car::recode(dict$RMM101, "'Disapprove Strongly'=1;
                             'Disapprove Somewhat'=2;
                             'Disapprove Slightly'=3;
                             'Neutral'=4;
                             'Approve Slightly'=5;
                             'Approve Somewhat'=6;
                             'Approve Strongly'=7")

dict$approve_b_before = ifelse(dict$approve_before > 4, 1, 0)

dict$approve_after = car::recode(dict$RMM102, "'Disapprove Strongly'=1;
                            'Disapprove Somewhat'=2;
                            'Disapprove Slightly'=3;
                            'Neutral'=4;
                            'Approve Slightly'=5;
                            'Approve Somewhat'=6;
                            'Approve Strongly'=7")

dict$approve_b_after = ifelse(dict$approve_after > 4, 1, 0)

dict$negpub = ifelse(dict$RMM101_t1=="", 0, 1)

dict$covert = ifelse(dict$RMM101_t2=="The government informed the American public about the operation.", 0, 1)

dict$success = ifelse(dict$RMM102_t3=="successful in removing the dictator from power and the situation has stabilized.", 1, 0)

dict$dict = rep(1, nrow(dict))

dict = subset(dict, select = c(caseid, region, approve_before, 
                               approve_after, approve_b_before,
                               approve_b_after, negpub, 
                               covert, success, dict))

# Clean Civil War Scenario

civ$region = civ$civ_region
civ$region = ifelse(civ$region=="the Middle East", "Middle East", civ$region)

civ$approve_before = car::recode(civ$RMM201, "'Disapprove Strongly'=1;
                            'Disapprove Somewhat'=2;
                            'Disapprove Slightly'=3;
                            'Neutral'=4;
                            'Approve Slightly'=5;
                            'Approve Somewhat'=6;
                            'Approve Strongly'=7")

civ$approve_b_before = ifelse(civ$approve_before > 4, 1, 0)

civ$approve_after = car::recode(civ$RMM202, "'Disapprove Strongly'=1;
                           'Disapprove Somewhat'=2;
                           'Disapprove Slightly'=3;
                           'Neutral'=4;
                           'Approve Slightly'=5;
                           'Approve Somewhat'=6;
                           'Approve Strongly'=7")

civ$approve_b_after = ifelse(civ$approve_after > 4, 1, 0)

civ$negpub = ifelse(civ$RMM201_t1=="", 0, 1)

civ$covert = ifelse(civ$RMM201_t2=="Covert", 1, 0)

civ$success = ifelse(civ$RMM202_t3=="successful in supporting the rebels and the civil war has ended.", 1, 0)

civ$dict = rep(0, nrow(civ))

civ = subset(civ, select = c(caseid, region, approve_before, 
                             approve_after, approve_b_before,
                             approve_b_after, negpub, 
                             covert, success, dict))
full2 = rbind(civ, dict)

#write.csv(full2, "2_exp2_data.csv")

# Experiment 3 (Non-Operational / Deceit) ---------------------------------

e = read.csv("3_exp3_raw.csv", stringsAsFactors = FALSE)

e$start_time = str_sub(e$start_time, 10, -1)
e$start_time = parse_date_time(e$start_time, order = "H:M")

e$rmm_starttime = str_sub(e$rmm_starttime, 1, -4)
e$rmm_starttime = parse_date_time(e$rmm_starttime, order = "H:M")

e$time_pretreat = as.numeric(difftime(e$rmm_starttime, e$start_time, units = "mins"))

e = subset(e, time_pretreat > 3)

#Code Civil War Scenario Outcomes
e$RMM201_t2 = ifelse(e$RMM201_nocov=="", "Covert", "Not Covert")
e$RMM201 = ifelse(e$RMM201_nocov!="", e$RMM201_nocov, e$RMM202_cov)

#Separate Scenarios

dict = subset(e, select = c("caseid", "RMM101", "RMM102", 
                            "dict_region", "RMM101_t1", "RMM101_t2",
                            "RMM102_t3"))

civ = subset(e, select = c("caseid", "RMM201", "RMM202", 
                           "civ_region", "RMM201_t1", "RMM201_t2",
                           "RMM202_t3"))

# Clean Dictator Scenario

dict$region = dict$dict_region
dict$region = ifelse(dict$region=="the Middle East", "Middle East", dict$region)

dict$approve_before = car::recode(dict$RMM101, "'Disapprove Strongly'=1;
                             'Disapprove Somewhat'=2;
                             'Disapprove Slightly'=3;
                             'Neutral'=4;
                             'Approve Slightly'=5;
                             'Approve Somewhat'=6;
                             'Approve Strongly'=7")

dict$approve_b_before = ifelse(dict$approve_before > 4, 1, 0)

dict$approve_after = car::recode(dict$RMM102, "'Disapprove Strongly'=1;
                            'Disapprove Somewhat'=2;
                            'Disapprove Slightly'=3;
                            'Neutral'=4;
                            'Approve Slightly'=5;
                            'Approve Somewhat'=6;
                            'Approve Strongly'=7")

dict$approve_b_after = ifelse(dict$approve_after > 4, 1, 0)

dict$military = ifelse(dict$RMM101_t1=="send in a small military force to assist the rebels.", 1, 0)

dict$covert_deceit = ifelse(dict$RMM101_t2=="The government informed the American public about the operation.", 0, 1)

dict$success = ifelse(dict$RMM102_t3=="successful in removing the dictator from power and the situation has stabilized.", 1, 0)

dict$dict = rep(1, nrow(dict))

dict = subset(dict, select = c(caseid, region, approve_before, 
                               approve_after, approve_b_before,
                               approve_b_after, military, 
                               covert_deceit, success, dict))

# Clean Civil War Scenario

civ$region = civ$civ_region
civ$region = ifelse(civ$region=="the Middle East", "Middle East", civ$region)

civ$approve_before = car::recode(civ$RMM201, "'Disapprove Strongly'=1;
                            'Disapprove Somewhat'=2;
                            'Disapprove Slightly'=3;
                            'Neutral'=4;
                            'Approve Slightly'=5;
                            'Approve Somewhat'=6;
                            'Approve Strongly'=7")

civ$approve_b_before = ifelse(civ$approve_before > 4, 1, 0)

civ$approve_after = car::recode(civ$RMM202, "'Disapprove Strongly'=1;
                           'Disapprove Somewhat'=2;
                           'Disapprove Slightly'=3;
                           'Neutral'=4;
                           'Approve Slightly'=5;
                           'Approve Somewhat'=6;
                           'Approve Strongly'=7")

civ$approve_b_after = ifelse(civ$approve_after > 4, 1, 0)

civ$military = ifelse(civ$RMM201_t1=="send in a small military force to assist the rebels.", 1, 0)

civ$covert_deceit = ifelse(civ$RMM201_t2=="Covert", 1, 0)

civ$success = ifelse(civ$RMM202_t3=="successful in supporting the rebels and the civil war has ended.", 1, 0)

civ$dict = rep(0, nrow(civ))

civ = subset(civ, select = c(caseid, region, approve_before, 
                             approve_after, approve_b_before,
                             approve_b_after, military, 
                             covert_deceit, success, dict))
full3 = rbind(civ, dict)

#write.csv(full3, "2_exp3_data.csv")


# Experiment 4 (Robustness Check: Non-Sequential Experiment 1) -----------------------------

e = read.csv("3_exp4_raw.csv", stringsAsFactors = FALSE)

e$start_time = str_sub(e$start_time, 10, -1)
e$start_time = parse_date_time(e$start_time, order = "H:M")

e$rmm_starttime = str_sub(e$rmm_starttime, 1, -4)
e$rmm_starttime = parse_date_time(e$rmm_starttime, order = "H:M")

e$time_pretreat = as.numeric(difftime(e$rmm_starttime, e$start_time, units = "mins"))

e = subset(e, time_pretreat > 3)

#Code Civil War Scenario Outcomes
e$RMM201_t2 = ifelse(e$RMM201_nocov=="", "Covert", "Not Covert")
e$RMM201 = ifelse(e$RMM201_nocov!="", e$RMM201_nocov, e$RMM202_cov)

#Separate Scenarios

dict = subset(e, select = c("caseid", "RMM101",
                            "dict_region", "RMM101_t1", "RMM101_t2",
                            "RMM102_t3"))

civ = subset(e, select = c("caseid", "RMM201", 
                           "civ_region", "RMM201_t1", "RMM201_t2",
                           "RMM202_t3"))

# Clean Dictator Scenario

dict$region = dict$dict_region
dict$region = ifelse(dict$region=="the Middle East", "Middle East", dict$region)

dict$approve = car::recode(dict$RMM101, "'Disapprove Strongly'=1;
                             'Disapprove Somewhat'=2;
                             'Disapprove Slightly'=3;
                             'Neutral'=4;
                             'Approve Slightly'=5;
                             'Approve Somewhat'=6;
                             'Approve Strongly'=7")

dict$approve_b = ifelse(dict$approve > 4, 1, 0)

dict$military = ifelse(dict$RMM101_t1=="send in a small military force to assist the rebels.", 1, 0)

dict$covert = ifelse(dict$RMM101_t2=="The government informed the American public about the operation.", 0, 1)

dict$success = ifelse(dict$RMM102_t3=="successful in removing the dictator from power and the situation had stabilized.", 1, 0)

dict$dict = rep(1, nrow(dict))

dict = subset(dict, select = c(caseid, region, approve,
                               approve_b, military, 
                               covert, success, dict))

# Clean Civil War Scenario

civ$region = civ$civ_region
civ$region = ifelse(civ$region=="the Middle East", "Middle East", civ$region)

civ$approve = car::recode(civ$RMM201, "'Disapprove Strongly'=1;
                            'Disapprove Somewhat'=2;
                            'Disapprove Slightly'=3;
                            'Neutral'=4;
                            'Approve Slightly'=5;
                            'Approve Somewhat'=6;
                            'Approve Strongly'=7")

civ$approve_b = ifelse(civ$approve > 4, 1, 0)

civ$military = ifelse(civ$RMM201_t1=="send in a small military force to assist the rebels.", 1, 0)

civ$covert = ifelse(civ$RMM201_t2=="Covert", 1, 0)

civ$success = ifelse(civ$RMM202_t3=="successful in supporting the rebels and the civil war had ended.", 1, 0)

civ$dict = rep(0, nrow(civ))

civ = subset(civ, select = c(caseid, region, approve,
                             approve_b, military, 
                             covert, success, dict))
full4 = rbind(civ, dict)

#write.csv(full4, "2_exp4_data.csv")


# Experiment 2 (With Manipulation Check) ----------------------------------

e = read.csv("3_exp2_raw_mcheck.csv", stringsAsFactors = FALSE)

# Remove speeders (pre-treatment)

e$start_time = str_sub(e$start_time, 10, -1)
e$start_time = parse_date_time(e$start_time, order = "H:M")

e$rmm_starttime = str_sub(e$rmm_starttime, 1, -4)
e$rmm_starttime = parse_date_time(e$rmm_starttime, order = "H:M")

e$time_pretreat = as.numeric(difftime(e$rmm_starttime, e$start_time, units = "mins"))

e = subset(e, time_pretreat > 3)

#Code Civil War Scenario Outcomes
e$RMM201_t2 = ifelse(e$RMM201_nocov=="", "Covert", "Not Covert")
e$RMM201 = ifelse(e$RMM201_nocov!="", e$RMM201_nocov, e$RMM202_cov)

#Code order of scenarios
e$dict_first = ifelse(str_sub(e$rmm_order, -1, -1)==3, 1, 0)

#Code whether passed the manipulation check
e$RMM_mcheck = ifelse(e$RMM_mcheck=="The government informed the American public about the operation.", "Not Covert", e$RMM_mcheck)
e$RMM_mcheck = ifelse(e$RMM_mcheck=="The government kept the operation completely secret from the American public.", "Covert", e$RMM_mcheck)
e$RMM_mcheck = ifelse(e$RMM_mcheck=="I don't know.", "Don't Know", e$RMM_mcheck)

#Correct MCheck
e$passed_mcheck = ifelse(e$dict_first==1 & e$RMM201_t2=="Covert" & e$RMM_mcheck=="Covert", 1, NA)
e$passed_mcheck = ifelse(e$dict_first==1 & e$RMM201_t2=="Not Covert" & e$RMM_mcheck=="Not Covert", 1, e$passed_mcheck)
e$passed_mcheck = ifelse(e$dict_first==0 & e$RMM201_t2=="Not Covert" & e$RMM_mcheck=="Covert", 1, e$passed_mcheck)
e$passed_mcheck = ifelse(e$dict_first==0 & e$RMM201_t2=="Covert" & e$RMM_mcheck=="Not Covert", 1, e$passed_mcheck)

## Incorrect MCheck
e$passed_mcheck = ifelse(e$dict_first==1 & e$RMM201_t2=="Covert" & e$RMM_mcheck=="Not Covert", 0, e$passed_mcheck)
e$passed_mcheck = ifelse(e$dict_first==1 & e$RMM201_t2=="Not Covert" & e$RMM_mcheck=="Covert", 0, e$passed_mcheck)
e$passed_mcheck = ifelse(e$dict_first==0 & e$RMM201_t2=="Not Covert" & e$RMM_mcheck=="Not Covert", 0, e$passed_mcheck)
e$passed_mcheck = ifelse(e$dict_first==0 & e$RMM201_t2=="Covert" & e$RMM_mcheck=="Covert", 0, e$passed_mcheck)
e$passed_mcheck = ifelse(e$RMM_mcheck=="Don't Know", 0, e$passed_mcheck)

e = subset(e, passed_mcheck==1)

#Separate Scenarios

dict = subset(e, select = c("caseid", "RMM101", "RMM102", 
                            "dict_region", "RMM101_t1", "RMM101_t2",
                            "RMM102_t3", "RMM_mcheck", "dict_first"))

civ = subset(e, select = c("caseid", "RMM201", "RMM202", 
                           "civ_region", "RMM201_t1", "RMM201_t2",
                           "RMM202_t3", "RMM_mcheck", "dict_first"))

# Clean Dictator Scenario

dict$region = dict$dict_region
dict$region = ifelse(dict$region=="the Middle East", "Middle East", dict$region)

dict$approve_before = car::recode(dict$RMM101, "'Disapprove Strongly'=1;
                                  'Disapprove Somewhat'=2;
                                  'Disapprove Slightly'=3;
                                  'Neutral'=4;
                                  'Approve Slightly'=5;
                                  'Approve Somewhat'=6;
                                  'Approve Strongly'=7")

dict$approve_b_before = ifelse(dict$approve_before > 4, 1, 0)

dict$approve_after = car::recode(dict$RMM102, "'Disapprove Strongly'=1;
                                 'Disapprove Somewhat'=2;
                                 'Disapprove Slightly'=3;
                                 'Neutral'=4;
                                 'Approve Slightly'=5;
                                 'Approve Somewhat'=6;
                                 'Approve Strongly'=7")

dict$approve_b_after = ifelse(dict$approve_after > 4, 1, 0)

dict$negpub = ifelse(dict$RMM101_t1=="", 0, 1)

dict$covert = ifelse(dict$RMM101_t2=="The government informed the American public about the operation.", 0, 1)

dict$success = ifelse(dict$RMM102_t3=="successful in removing the dictator from power and the situation has stabilized.", 1, 0)

dict$dict = rep(1, nrow(dict))

dict = subset(dict, select = c(caseid, region, approve_before, 
                               approve_after, approve_b_before,
                               approve_b_after, negpub, 
                               covert, success, dict))

# Clean Civil War Scenario

civ$region = civ$civ_region
civ$region = ifelse(civ$region=="the Middle East", "Middle East", civ$region)

civ$approve_before = car::recode(civ$RMM201, "'Disapprove Strongly'=1;
                                 'Disapprove Somewhat'=2;
                                 'Disapprove Slightly'=3;
                                 'Neutral'=4;
                                 'Approve Slightly'=5;
                                 'Approve Somewhat'=6;
                                 'Approve Strongly'=7")

civ$approve_b_before = ifelse(civ$approve_before > 4, 1, 0)

civ$approve_after = car::recode(civ$RMM202, "'Disapprove Strongly'=1;
                                'Disapprove Somewhat'=2;
                                'Disapprove Slightly'=3;
                                'Neutral'=4;
                                'Approve Slightly'=5;
                                'Approve Somewhat'=6;
                                'Approve Strongly'=7")

civ$approve_b_after = ifelse(civ$approve_after > 4, 1, 0)

civ$negpub = ifelse(civ$RMM201_t1=="", 0, 1)

civ$covert = ifelse(civ$RMM201_t2=="Covert", 1, 0)

civ$success = ifelse(civ$RMM202_t3=="successful in supporting the rebels and the civil war has ended.", 1, 0)

civ$dict = rep(0, nrow(civ))

civ = subset(civ, select = c(caseid, region, approve_before, 
                             approve_after, approve_b_before,
                             approve_b_after, negpub, 
                             covert, success, dict))
full2_mcheck = rbind(civ, dict)

#write.csv(full2_mcheck, "2_exp2_data_mcheck.csv")

